﻿namespace Nello
{
    using System;
    using System.Collections;

    public class StringUtil
    {
        public static string GetRandomString()
        {
            return GetRandomString(8);
        }

        public static string GetRandomString(int bits)
        {
            return GetRandomString("*".PadLeft(bits, '*'));
        }

        public static string GetRandomString(string template)
        {
            return StringRandom.Instance.GetRandomString(template);
        }

        public static string Join(ICollection co)
        {
            return Join(",", co);
        }

        public static string Join(IDictionary dic)
        {
            return Join("|", dic);
        }

        public static string Join(IEnumerable enu)
        {
            return Join(",", enu);
        }

        public static string Join(string sep, ICollection co)
        {
            string[] obj = new string[co.Count];
            co.CopyTo(obj, 0);
            return string.Join(sep, obj);
        }

        public static string Join(string sep, IDictionary dic)
        {
            string s = "";
            IDictionaryEnumerator ide = dic.GetEnumerator();
            while (ide.MoveNext())
            {
                object CS00001 = s;
                s = string.Concat(new object[] { CS00001, ide.Key, "=", ide.Value, sep });
            }
            return s.TrimEnd(sep.ToCharArray());
        }

        public static string Join(string sep, IEnumerable enu)
        {
            return Join(sep, enu, "");
        }

        public static string Join(string sep, IEnumerable enu, string quot)
        {
            string s = "";
            IEnumerator ien = enu.GetEnumerator();
            while (ien.MoveNext())
            {
                string CS00001 = s;
                s = CS00001 + quot + ien.Current.ToString() + quot + sep;
            }
            return s.TrimEnd(sep.ToCharArray());
        }
    }
}

